// js/login.js

document.addEventListener('DOMContentLoaded', () => {
    const loginForm = document.getElementById('loginForm');
    const usernameInput = document.getElementById('username');
    const passwordInput = document.getElementById('password');
    const loginMessage = document.getElementById('loginMessage');

    loginForm.addEventListener('submit', (event) => {
        event.preventDefault(); // Prevent default form submission

        const username = usernameInput.value;
        const password = passwordInput.value;

        const user = data.validateLogin(username, password);

        if (user) {
            data.setCurrentUser(user); // Store logged-in user info
            window.location.href = 'dashboard.html'; // Redirect to dashboard
        } else {
            loginMessage.textContent = '用户名或密码错误！';
            loginMessage.style.color = '#dc3545';
        }
    });
});
